import request from '@/utils/request'

/**
 * 附件相关接口
 */

/**
 * 获取附件列表
 * @param page 页码
 * @param size 每页数量
 * @param type 类型
 * @param groupId 分组ID
 * @param search 搜索条件
 */
export function getAttachmentList(page, size, type = 1, groupId, search) {
  search.group_id = groupId
  search.type = type
  return request({
    url: '/attachment/list',
    method: 'post',
    data: { page, size, search }
  })
}

/**
 * 上传附件
 * @param page 页码
 * @param size 每页数量
 * @param type 类型
 * @param groupId 分组ID
 * @param search 搜索条件
 */
export function UploadAttachment(page, size, type = 1, groupId, search) {
  return request({
    url: '/attachment/upload',
    method: 'post',
    data: { page, size, type, group_id: groupId, search }
  })
}

/**
 * 获取编辑表单
 * @param id 附件ID
 */
export function getAttachmentEdit(id) {
  return request({
    url: '/attachment/index/' + id + '/edit',
    method: 'get'
  })
}

/**
 * 删除附件
 * @param ids 附件ID数组
 */
export function deleteAttachment(ids) {
  return request({
    url: '/attachment/delete',
    method: 'post',
    data: { ids }
  })
}

/**
 * 移动附件
 * @param ids 附件ID数组
 * @param groupId 分组ID
 */
export function moveAttachment(ids, groupId) {
  return request({
    url: '/attachment/move',
    method: 'post',
    data: { ids, group_id: groupId }
  })
}

/**
 * 附件分组相关接口
 */

/**
 * 获取附件分组
 * @param type 类型
 */
export function getAttachmentGroupList(type) {
  return request({
    url: '/attachment/group',
    method: 'get',
    params: { type }
  })
}

/**
 * 获取分组表单
 * @param id 分组ID
 */
export function getAttachmentGroupForm(id) {
  if (id) {
    return request({
      url: '/attachment/group/' + id + '/edit',
      method: 'get'
    })
  } else {
    return request({
      url: '/attachment/group/create',
      method: 'get'
    })
  }
}

/**
 * 删除分组
 * @param id 分组ID
 */
export function delAttachmentGroup(id) {
  return request({
    url: '/attachment/group/' + id,
    method: 'delete'
  })
}
